package fr.alma.trajectory.rendering;

import javax.media.opengl.GL2;

/**
 * Classe permettant d'afficher en openGL 
 * la grille de cubes à partir d'un objet de type Space3D.
 * @author M2 ALMA 2011 Multimédia
 *
 */
public class GLSquelette {
	
	private GL2 gl;
	
	public GLSquelette(GL2 gl){
		this.gl = gl;
	}
	
	public void render(){
		gl.glPolygonMode(GL2.GL_FRONT_AND_BACK, GL2.GL_LINE);
		gl.glBegin(GL2.GL_QUADS);
		//gl.glTranslated(x, y, z);
		//TODO trouver technique pour dessiner la grille de cubes 
		gl.glEnd();
	}
	
	public void drawCube(double x, double y, double z){
		gl.glVertex3d(x + 1.0,y + 1.0,z );			// Top Right Of The Quad (Top)
        gl.glVertex3d(x ,y + 1.0,z );				// Top Left Of The Quad (Top)
        gl.glVertex3d(x ,y + 1.0,z + 1.0);			// Bottom Left Of The Quad (Top)
        gl.glVertex3d(x + 1.0,y + 1.0,z + 1.0);		// Bottom Right Of The Quad (Top)
        gl.glVertex3d(x + 1.0,y ,z + 1.0);			// Top Right Of The Quad (Bottom)
        gl.glVertex3d(x ,y ,z + 1.0);				// Top Left Of The Quad (Bottom)
        gl.glVertex3d(x ,y ,z );					// Bottom Left Of The Quad (Bottom)
        gl.glVertex3d(x + 1.0,y ,z );				// Bottom Right Of The Quad (Bottom)
        gl.glVertex3d(x + 1.0,y + 1.0,z + 1.0);		// Top Right Of The Quad (Front)
        gl.glVertex3d(x ,y + 1.0,z + 1.0);			// Top Left Of The Quad (Front)
        gl.glVertex3d(x ,y ,z + 1.0);				// Bottom Left Of The Quad (Front)
        gl.glVertex3d(x + 1.0,y ,z + 1.0);			// Bottom Right Of The Quad (Front)
        gl.glVertex3d(x + 1.0,y ,z);				// Top Right Of The Quad (Back)
        gl.glVertex3d(x ,y ,z );					// Top Left Of The Quad (Back)
        gl.glVertex3d(x ,y + 1.0,z );				// Bottom Left Of The Quad (Back)
        gl.glVertex3d(x + 1.0,y + 1.0,z);			// Bottom Right Of The Quad (Back)
        gl.glVertex3d(x ,y + 1.0,z + 1.0);			// Top Right Of The Quad (Left)
        gl.glVertex3d(x ,y + 1.0,z );				// Top Left Of The Quad (Left)
        gl.glVertex3d(x ,y,z );						// Bottom Left Of The Quad (Left)
        gl.glVertex3d(x ,y ,z + 1.0);				// Bottom Right Of The Quad (Left)
        gl.glVertex3d(x + 1.0,y + 1.0,z );			// Top Right Of The Quad (Right)
        gl.glVertex3d(x + 1.0,y + 1.0,z + 1.0);		// Top Left Of The Quad (Right)
        gl.glVertex3d(x + 1.0,y ,z + 1.0);			// Bottom Left Of The Quad (Right)
        gl.glVertex3d(x + 1.0,y ,z );				// Bottom Right Of The Quad (Right)			
	}
	
	public static void drawCubeWithGL(GL2 gl2, double x, double y, double z, double dim){
		gl2.glVertex3d(x + dim,y + dim,z );			// Top Right Of The Quad (Top)
        gl2.glVertex3d(x ,y + dim,z );				// Top Left Of The Quad (Top)
        gl2.glVertex3d(x ,y + dim,z + dim);			// Bottom Left Of The Quad (Top)
        gl2.glVertex3d(x + dim,y + dim,z + dim);		// Bottom Right Of The Quad (Top)
        gl2.glVertex3d(x + dim,y ,z + dim);			// Top Right Of The Quad (Bottom)
        gl2.glVertex3d(x ,y ,z + dim);				// Top Left Of The Quad (Bottom)
        gl2.glVertex3d(x ,y ,z );					// Bottom Left Of The Quad (Bottom)
        gl2.glVertex3d(x + dim,y ,z );				// Bottom Right Of The Quad (Bottom)
        gl2.glVertex3d(x + dim,y + dim,z + dim);		// Top Right Of The Quad (Front)
        gl2.glVertex3d(x ,y + dim,z + dim);			// Top Left Of The Quad (Front)
        gl2.glVertex3d(x ,y ,z + dim);				// Bottom Left Of The Quad (Front)
        gl2.glVertex3d(x + dim,y ,z + dim);			// Bottom Right Of The Quad (Front)
        gl2.glVertex3d(x + dim,y ,z);				// Top Right Of The Quad (Back)
        gl2.glVertex3d(x ,y ,z );					// Top Left Of The Quad (Back)
        gl2.glVertex3d(x ,y + dim,z );				// Bottom Left Of The Quad (Back)
        gl2.glVertex3d(x + dim,y + dim,z);			// Bottom Right Of The Quad (Back)
        gl2.glVertex3d(x ,y + dim,z + dim);			// Top Right Of The Quad (Left)
        gl2.glVertex3d(x ,y + dim,z );				// Top Left Of The Quad (Left)
        gl2.glVertex3d(x ,y,z );						// Bottom Left Of The Quad (Left)
        gl2.glVertex3d(x ,y ,z + dim);				// Bottom Right Of The Quad (Left)
        gl2.glVertex3d(x + dim,y + dim,z );			// Top Right Of The Quad (Right)
        gl2.glVertex3d(x + dim,y + dim,z + dim);		// Top Left Of The Quad (Right)
        gl2.glVertex3d(x + dim,y ,z + dim);			// Bottom Left Of The Quad (Right)
        gl2.glVertex3d(x + dim,y ,z );				// Bottom Right Of The Quad (Right)			
	}
}